import es
from urllib import urlopen

class Auth(object):
    def __init__(self):
        self.admins = []
    def updateAdminList(self, url=None):
        es.dbgmsg(0, 'Updateing Admin List...')
        if url:
            while len(self.admins):
                self.admins.pop(0)
            for line in urlopen(url):
                self.admins.append(line[:line.rfind('\n')])
            es.dbgmsg(0, 'Admin List updated successfully!')
            es.dbgmsg(0, 'Total amount of Admins: %s' % len(self.admins))
            i = 0
            for admin in self.admins:
                i += 1
                es.dbgmsg(0, 'Admin #%s: %s' % (i, admin))
        else:
            es.dbgmsg(0, 'Aborting update. No URL specified.')
    def isAuthed(self, userid):
        if es.getplayersteamid(userid) in self.admins:
            return 1
        return 0
auth = Auth()

def isAuthed(userid):
    return auth.isAuthed(userid)

def updateAdminList(url):
    auth.updateAdminList(url)
